package cn.apptec.test.ssm.aspect;


import cn.apptec.test.ssm.annotation.SwitchDS;
import cn.apptec.test.ssm.enumeration.DatasourceEnum;
import cn.apptec.test.ssm.utils.DataSourceContextHolder;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class DbAspect {
    @Before(value = "@annotation(ds)")
    public void doAfterReturning(SwitchDS ds) throws Throwable {
        DatasourceEnum value = ds.value();
        DataSourceContextHolder.setDbType(value.getDs());
    }

    @AfterReturning(value = "@annotation(ds)")
    public void doAfter(SwitchDS ds) throws Throwable {
        DataSourceContextHolder.setDbType(DatasourceEnum.LOCAL.getDs());
    }
}